<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.model.User"%>

<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="../images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 系统管理&gt;&gt; 职位角色管理
</div>

<%
{
%>
<div class="tt">管理职位与角色映射</div>
<div class="content">
	<table align="center" border="0" width="800" cellpadding="0"
		cellspacing="0">
		<tr>
			<td class="td1" height="35">
				<span style="margin-left: 30px">一级单位：</span>
				<span id="depart1SelectSpan">
				<%@include file="depart_select/depart1_select_section.jsp" %>
				</span>
				<br />
				<span style="margin-left: 30px">二级单位：</span>
				<span id="depart2SelectSpan">
				<%@include file="depart_select/depart2_select_section.jsp" %>
				</span>
				<a href="javascript:" onclick="deleteDepart2()" style="margin-left: 10px">删除</a>
				<a href="javascript:" onclick="addDepart2()" style="margin-left: 10px">增加</a>
				<br />
				<span style="margin-left: 30px">职位：</span>
				<span id="depart3SelectSpan">
				<%@include file="depart_select/depart3_select_section.jsp" %>
				</span>
				<a href="javascript:" onclick="deleteDepart3()" style="margin-left: 10px">删除</a>
				<a href="javascript:" onclick="addDepart3()" style="margin-left: 10px">增加</a>
			</td>
			<td  class="td1" height="35">				
				<span style="margin-left: 30px">角色：</span>
				<span id="roleSelectSpan">
				<%@include file="role_select/role_select_section.jsp" %>
				</span>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="td1" align="center">
				<input type="button" value="更新" onclick="updateDepart3Role()" />
			</td>
		</tr>
	</table>
</div>
<script type="text/javascript">
function selectDepart1() {
	var depart1ID = getElementValueByID('depart1');
	loadPageSection('depart_select/depart2_select_section.jsp', 'depart2SelectSpan', {depart1ID:depart1ID}, false, function(){ selectDepart2();});
}

function selectDepart2() {
	var depart1ID = getElementValueByID('depart1');
	var depart2ID = getElementValueByID('depart2');
	loadPageSection('depart_select/depart3_select_section.jsp', 'depart3SelectSpan', {depart1ID:depart1ID, depart2ID:depart2ID}, false, function(){selectDepart3();});
}

function selectDepart3() {
	var depart3ID = getElementValueByID('depart3');
	loadPageSection('role_select/role_select_section.jsp', 'roleSelectSpan', {depart3ID:depart3ID, selectedBy:'<%=Constants.CONST_SELECTED_BY_DEPART3ID%>'}, false);
}

function addDepart2(){
	var depart1ID = getElementValueByID('depart1');

	loadPageSection(
			'<%=request.getContextPath()%>/admin/add_depart2.jsp', 
			'mainContentDiv', 
			{
				depart1ID:depart1ID
			}, 
			true
	);		
}

function addDepart3(){
	var depart1ID = getElementValueByID('depart1');
	var depart2ID = getElementValueByID('depart2');
	var roleID =  getElementValueByID('role');

	loadPageSection(
			'<%=request.getContextPath()%>/admin/add_depart3.jsp', 
			'mainContentDiv', 
			{
				depart1ID:depart1ID, 
				depart2ID:depart2ID,
				roleID: roleID
			}, 
			true
	);	
}

function deleteDepart2() {
	var depart1ID = getElementValueByID('depart1');
	var depart2ID = getElementValueByID('depart2');
	
	$.dialog.confirm('该二级单位删除后无法恢复，将影响与这个单位相关联的问题处理，请谨慎删除！您是否确认删除？', function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'delete_depart2_process.jsp',
			data:{			
				depart2ID: depart2ID
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {					
						$.dialog('删除成功！', function() { 
							loadPageSection(
									'<%=request.getContextPath()%>/admin/department3_role.jsp', 
									'mainContentDiv', 
									{
										depart1ID:depart1ID
									}, 
									true
							);
						});					
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	});	
}

function deleteDepart3(){
	var depart1ID = getElementValueByID('depart1');
	var depart2ID = getElementValueByID('depart2');
	var depart3ID = getElementValueByID('depart3');
	$.dialog.confirm('该职位删除后无法恢复，请谨慎删除，您是否确认删除？', function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'delete_depart3_process.jsp',
			data:{			
				depart3ID: depart3ID
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {					
						$.dialog('删除成功！', function() { 
							loadPageSection(
									'<%=request.getContextPath()%>/admin/department3_role.jsp', 
									'mainContentDiv', 
									{
										depart1ID:depart1ID, 
										depart2ID:depart2ID
									}, 
									true
							);
						});					
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	});	
}


function updateDepart3Role() {
	var depart1ID = getElementValueByID('depart1');
	var depart2ID = getElementValueByID('depart2');
	var depart3ID = getElementValueByID('depart3');
	var roleID =  getElementValueByID('role');
	if(depart3ID == '' || depart3ID == null || depart3ID == 'undefined'){
		$.dialog.alert('请先选择职位');
		return;
	}
	
$.dialog.confirm('您确认修改吗？', function(){
	openWaitingDialog('waitingDialog');
	$.ajax({
		type:'post',
		url:'update_department3_role_process.jsp',
		data:{			
			depart3ID: depart3ID,
			roleID: roleID
		},
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				closeWaitingDialog('waitingDialog');
				if (obj.isSuccess == 'true') {					
					$.dialog('更新成功！', function() { 
						loadPageSection(
								'<%=request.getContextPath()%>/admin/department3_role.jsp', 
								'mainContentDiv', 
								{
									depart1ID:depart1ID, 
									depart2ID:depart2ID, 
									depart3ID:depart3ID, 
									roleID:roleID
								}, 
								true
						); 
					});					
				} else {
					$.dialog.alert(obj.error);
				}
			}
		}
	});
});
}
selectDepart1();
</script>
<%
}
%>

